package com.qwz.example.abssegment;

import com.qwz.example.realize.MessageEmail;
import com.qwz.example.realize.MessageImplementor;
import com.qwz.example.realize.MessageMobile;
import com.qwz.example.realize.MessageSMS;
/**
* @Description: 抽象的消息对象 简单工厂模式实现 直接在抽像方法中实现
* @Package com.qwz.example.abssegment.AbstractMessageFactory
* @author Qiuwuzhi
* @date 2019/12/20 16:09
* @version V1.0
*/
public class AbstractMessageFactory {

    protected MessageImplementor implementor;

    /**
     * 简单工厂模式实现
     * @param type
     */
    public AbstractMessageFactory(int type) {
        switch (type) {
            case 1:
                implementor = new MessageSMS();
                break;
            case 2:
                implementor = new MessageEmail();
                break;
            case 3:
                implementor = new MessageMobile();
                break;
        }

    }

    /**
     * 发送消息，转调实现部分的方法
     *
     * @param message
     * @param toUser
     */
    public void sendMessage(String message, String toUser) {
        implementor.send(message, toUser);
    }
}
